package javabase;

import java.util.ArrayList;
import java.util.NoSuchElementException;

/**
 * Created by mHandler on 2018/5/21 0021.
 * Description:基于ArrayList的队列实现
 */
public class ArrayListToQueue<T> {

    private ArrayList<T> arrayList = new ArrayList<>();

    public boolean offer (T t){
        return arrayList.add(t);
    }

    public T peek(){
        if (arrayList.size()>0)
            return arrayList.get(0);
        else
            return null;
    }

    public T element() {
        if (arrayList == null || arrayList.size() < 1){
            throw new NoSuchElementException("null Queue");
        }else
            return arrayList.get(0);
    }

    public T poll(){
        T element = null;
        if (arrayList.size() > 0){
            element = arrayList.get(0);
            arrayList.remove(0);
            return element;
        }else
            return element;
    }

    public T remove(){
        T element = null;
        if (arrayList == null || arrayList.size() < 1){
            throw  new NoSuchElementException("null Queue");
        }else {
            element = arrayList.get(0);
            arrayList.remove(0);
            return element;
        }
    }

    public boolean isEmpty(){
        return arrayList.isEmpty();
    }

    public String toString(){
        return arrayList.toString();
    }

    public static void main(String[] args) {
//        String s = "abcdefg";
//        System.out.println(""+s.indexOf("bc"));
//        System.out.println(""+s.indexOf("de"));

        String s1 = "ab";
        String s2 = "abc";
        String s3 = s1 + "c";
        System.out.println(s3 == s2);
    }


}
